package com.sakura.thread.chapter1.test7;

/**
 * Created by apple on 2018/12/11.
 */
public class Difference {

    public static void test1() throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                for(;;){

                }
            }
        });

        threadOne.start();

        threadOne.interrupt();

        System.out.println("isInterrupted:"+threadOne.isInterrupted());

        System.out.println("interrupted:"+Thread.interrupted());

        threadOne.join();

        System.out.println("main is over");
    }

    public static void test2() throws InterruptedException {
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!Thread.interrupted()){

                }

                System.out.println("threadOne isInterrupted:"+Thread.currentThread().isInterrupted());
            }
        });

        threadOne.start();

        threadOne.interrupt();

        threadOne.join();

        System.out.println("main is over");
    }

    public static void main(String[] args) throws InterruptedException {
        //test1();

        test2();
    }
}
